<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>字符串的语法高亮</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.highlight-file.html">highlight_file</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ignore-user-abort.html">ignore_user_abort</a></div>
 <div class="up"><a href="ref.misc.html">杂项 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.highlight-string" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">highlight_string</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">highlight_string</span> &mdash; <span class="dc-title">字符串的语法高亮</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.highlight-string-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>highlight_string</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$return</code><span class="initializer"> = false</span></span>
  ] )</div>

  <p class="simpara">
   使用PHP内置的语法高亮器所定义的颜色，打印输出或者返回输出或者返回语法高亮版本的PHP代码。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.highlight-string-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">str</code></em></dt>

     <dd>

      <p class="para">
       需要高亮的PHP代码，应当包含开始标签。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">return</code></em></dt>

     <dd>

      <p class="para">
       设置该参数为 <strong><code>TRUE</code></strong> 使函数返回高亮后的代码。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.highlight-string-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
     如果 <em><code class="parameter">return</code></em> 设置为 <strong><code>TRUE</code></strong>，高亮后的代码不会被打印输出，而是以字符串的形式返回。
     高亮成功返回 <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.highlight-string-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.2.0</td>
       <td>
        添加了 <em><code class="parameter">return</code></em> 的参数。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.highlight-string-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3687">
    <p><strong>Example #1 <span class="function"><strong>highlight_string()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />highlight_string</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;?php&nbsp;phpinfo();&nbsp;?&gt;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     PHP4中，上例会输出:
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;code&gt;&lt;font color=&quot;#000000&quot;&gt;
&lt;font color=&quot;#0000BB&quot;&gt;&amp;lt;?php phpinfo&lt;/font&gt;&lt;font color=&quot;#007700&quot;&gt;(); &lt;/font&gt;&lt;font color=&quot;#0000BB&quot;&gt;?&amp;gt;&lt;/font&gt;
&lt;/font&gt;
&lt;/code&gt;
</pre></div>
    </div>
    <div class="example-contents"><p>
     PHP5中，上例会输出:
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php phpinfo&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(); &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/code&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.highlight-string-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">当使用了<em><code class="parameter">return</code></em>
参数时，本函数使用其内部输出缓冲，因此不能在
<span class="function"><a href="function.ob-start.html" class="function">ob_start()</a></span> 回调函数的内部使用。</p></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.highlight-string-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.highlight-file.html" class="function" rel="rdfs-seeAlso">highlight_file()</a> - 语法高亮一个文件</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.highlight-file.html">highlight_file</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ignore-user-abort.html">ignore_user_abort</a></div>
 <div class="up"><a href="ref.misc.html">杂项 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
